package com.eshin;

import java.util.concurrent.Executor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import com.eshin.banner.MyBanner;


/**
 * 命令行参数
来自于java:comp/env的JNDI属性
Java系统属性（System.getProperties()）
操作系统环境变量
只有在random.*里包含的属性会产生一个RandomValuePropertySource
在打包的jar外的应用程序配置文件（application.properties，包含YAML和profile变量）
在打包的jar内的应用程序配置文件（application.properties，包含YAML和profile变量）
在@Configuration类上的@PropertySource注解
默认属性（使用SpringApplication.setDefaultProperties指定）
//通过该注解价值properties文件内的配置  
//通过prefix执行properties配置的前缀  
@ConfigurationProperties(prefix = "user") 
 * 
*/
/** 
 * 是Spring Boot项目的核心注解,主要是开启自动配置 
 */  
@SpringBootApplication// same as @Configuration @EnableAutoConfiguration @ComponentScan 
/**
 * proxy-target-class属性值决定是基于接口的还是基于类的代理被创建。
 * 如果proxy-target-class 属性值被设置为true，那么基于类的代理将起作用
 * （这时需要cglib库）。如果proxy-target-class属值被设置为false或者这个
 * 属性被省略，那么标准的JDK 基于接口的代理
 *
 */
@EnableAsync(proxyTargetClass=true)
public class BootdemoApplication {

	public static void main(String[] args) {
//		SpringApplication.run(BootdemoApplication.class, args);
		SpringApplication app = new SpringApplication(BootdemoApplication.class);
	    app.setBanner(new MyBanner());
//	    app.setBannerMode(Mode.OFF);
	    app.run(args);
		System.out.println("demo is runing...");
	}
	
	
	@Bean
	public Executor myExecutor() {  
		ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();  
		executor.setCorePoolSize(5);  
		executor.setMaxPoolSize(10);  
		executor.setQueueCapacity(25);
		executor.setThreadNamePrefix("myExecutor_methhod_");
		executor.initialize();  
		return executor;  
	}  
	@Bean("myExecutor")
	public Executor getAsyncExecutor() {  
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();  
        executor.setCorePoolSize(5);  
        executor.setMaxPoolSize(10);  
        executor.setQueueCapacity(25);
        executor.setThreadNamePrefix("myExecutor_");
        executor.initialize();  
        return executor;  
   }  
	@Bean("myExecutor1")
	public Executor getAsyncExecutor1() {  
		ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();  
		executor.setCorePoolSize(5);  
		executor.setMaxPoolSize(10);  
		executor.setQueueCapacity(25);
		executor.setThreadNamePrefix("myExecutor1_");
		executor.initialize();  
		return executor;  
	}  
}
